<template>
  <el-card shadow="never" class="aui-card--fill">
    <el-form :inline="true" v-model="SearchForm"  @keydown.enter.native.prevent="getDataList()">
      <el-form-item>
        <el-input v-model="SearchForm.susername" placeholder="学生学号" clearable></el-input>
      </el-form-item>
      <el-form-item>
        <el-button @click="getDataList()">查询</el-button>
      </el-form-item>
    </el-form>
    <el-table :data="dataList" border v-loading="dataListLoading" @selection-change="selectionChangeHandle"
      >
      <el-table-column prop="susername" header-align="center" align="center"  label="学生学号">
      </el-table-column>
      <el-table-column prop="stuName" header-align="center" align="center"  label="姓名">
      </el-table-column>
      <el-table-column prop="grade" header-align="center" align="center"   :show-overflow-tooltip="true" label="指导成绩">
      </el-table-column>
      <el-table-column prop="grade1" header-align="center"  :show-overflow-tooltip="true" align="center" label="评阅成绩">
      </el-table-column>
      <el-table-column prop="grade2" header-align="center"  :show-overflow-tooltip="true" align="center" label="答辩成绩">
      </el-table-column>
      <el-table-column prop="average" header-align="center"  :show-overflow-tooltip="true" align="center" label="综合成绩">
      </el-table-column>
      <el-table-column fixed="right" header-align="center" align="center" label="操作">
          <template slot-scope="scope">
            <el-button type="text" size="small" @click="addOrUpdateHandle(scope.row)">录入成绩
            </el-button>
            <!-- <el-button type="text" size="small" @click="deleteHandle(scope.row.cgyName)">
              删除</el-button> -->
          </template>
        </el-table-column>
    </el-table>
    <el-pagination @size-change="sizeChangeHandle" @current-change="currentChangeHandle" :current-page="pageIndex"
      :page-sizes="[10, 20, 50, 100]" :page-size="pageSize" :total="totalPage"
      layout="total, sizes, prev, pager, next, jumper">
    </el-pagination>
    <!-- 弹窗, 新增 / 修改 -->
    <add-or-update v-if="addOrUpdateVisible" ref="addOrUpdate" @refreshDataList="getDataList"></add-or-update>
  </el-card>
</template>

<script>
import AddOrUpdate from '@/views/Teacher/grade-add-or-update.vue'
import servicesApi from '@/services/servicesApi';
import debounce from 'lodash/debounce';
export default {
  data() {
    return {
      SearchForm: {
        susername: ''
      },
      dataList: [
        { 
          susername: '232',
          stuName: 'drwe',
          grade: 78,
          grade1: 87,
          grade2: 54,
          average: 76
        }
      ],
      pageIndex: 1,
      pageSize: 10,
      totalPage: 0,
      dataListLoading: false,
      addOrUpdateVisible: false,
    }
  },
  components: {
    AddOrUpdate
  },
  created() {
    this.getDataList()
  },
  methods: {
    // 获取数据列表
    getDataList: debounce(function() {
      this.dataListLoading = true
      let pageInfo = {
        current: this.pageIndex,
        size: this.pageSize,
       name: this.SearchForm.susername
      }
      servicesApi.getTmguidance(pageInfo).then(res => {
        // console.log(res.data)
        let code =res.data.code
        let data = res.data.data
        if (code===200) {
          // console.log(data)
          this.dataList = data.list
          this.totalPage = data.total
        } else {
          this.dataList = []
          this.totalPage = 0
        }
        this.dataListLoading = false
      })
    }, 1000, { 'leading': true, 'trailing': false }),
    // 每页数
    sizeChangeHandle(val) {
      this.pageSize = val
      this.pageIndex = 1
      this.getDataList()
    },
    // 多选
    selectionChangeHandle(val) {
      this.dataListSelections = val
    },
    // 当前页
    currentChangeHandle(val) {
      this.pageIndex = val
      this.getDataList()
    },
    // 新增 / 修改
    addOrUpdateHandle(row) {
      this.addOrUpdateVisible = true
      this.$nextTick(() => {
         // 当数据被修改后使用这个方法，会回调获取更新后的dom再渲染出来
        this.$refs['addOrUpdate'].init(row)
      })
    },
  }
}
</script>
